#!/usr/bin/env python
# -*- coding:utf-8 -*- 
# Author: Jeokayne Ataier
import multiprocessing as mp

def job(x):
    return x*x

if __name__ == "__main__":
    pool = mp.Pool()
    res = pool.map(job,range(10)) #map可以传入多个数据(可迭代的类型),并且将返回值放入列表
    print(res)

    res = pool.apply_async(job,(2,))  #apply_async只能一个一个数值进行计算，返回一个对应的实例，真实返回值的获取需要用get()方法
    print(res.get())

    '''
    较为关键
    '''
    multi_res = [pool.apply_async(job,(i,)) for i in range(10)] #apply_async想要实现类似于map的效果，就需要借助迭代器
    print([res.get() for res in multi_res])


'''
运行结果
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
4
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
'''